
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  }
}

const DockerKey = '/jpower-auth'

module.exports = [
  // user login
  {
    url: `${DockerKey}/auth/login`,
    type: 'post',
    response: config => {
      const { loginId, grantType } = config.query
      const token = tokens[loginId]
      let code = 401
      let data = {}
      let msg = '用户账号或密码不正确'

      if (token || grantType) {
        code = 200
        data = {
          user: {
            userId: 1,
            clientCode: 1,
            loginId: 1,
            userName: 1,
            nickName: 1,
            otherCode: 1,
            telephone: 1,
            userType: 1,
            orgId: 1,
            roleIds: 1,
            isSysUser: 1
          },
          accessToken: 'accessToken:' + token,
          refreshToken: 'refreshToken' + token,
          tokenType: 'mock',
          expiresIn: 1800
        }
        msg = ''
      }

      return {
        code,
        data,
        message: msg
      }
    }
  },

  // get user info
  {
    url: '/vue-admin-template/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/vue-admin-template/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
